<?php
/**
 * 
 * @author Truonghm
 * 	Example 1
 *  $columns = new PhpExt_Tree_Columns();
	$columns->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Task","task","task",160, null, null, true, false));
	$columns->addColumn(PhpExt_Grid_ColumnConfigObject::createColumn("Duration","duration","duration",160, null, null, true, false));
	
	$treeGrid = new PhpExtUx_Tree_TreeGrid();
		
	$treeGrid->setTitle("tree grid")
			 ->setWidth(500)				 
			 ->setColumns($columns)
			 ->dataUrl("http://officex/treegrid-data.php");
	$treeGrid->setEnableDd(true);
	
	Example 2:----------------------------------------------------------------------
	
	$treeColumn = PhpExt_Javascript::stm("
			var treeColumn = [{
	            header: 'Task',
	            dataIndex: 'task',
	            width: 230
	        },{
	            header: 'Duration',
	            width: 100,
	            dataIndex: 'duration',
	            align: 'center',
	            sortType: 'asFloat',
	            tpl: new Ext.XTemplate('{duration:this.formatHours}', {
	                formatHours: function(v) {
	                    if(v < 1) {
	                        return Math.round(v * 60) + ' mins';
	                    } else if (Math.floor(v) !== v) {
	                        var min = v - Math.floor(v);
	                        return Math.floor(v) + 'h ' + Math.round(min * 60) + 'm';
	                    } else {
	                        return v + ' hour' + (v === 1 ? '' : 's');
	                    }
	                }
	            })
	        },{
	            header: 'Assigned To',
	            width: 150,
	            dataIndex: 'user'
	        }];
		");	
	
	$treeGrid = new PhpExtUx_Tree_TreeGrid();
		
	$treeGrid->setTitle("tree grid")
			 ->setWidth(500)				 
			 ->setColumnsVariable(PhpExt_Javascript::variable('treeColumn'))
			 ->dataUrl("http://officex/treegrid-data.php");
	$treeGrid->setEnableDd(true);
	
	$this->view->layout =Ofx_Extjs::OnReady(	
		$treeColumn,
		$treeGrid->getJavascript(false, "treeGrid"),
		.......
	);
		
 *
 */
class PhpExtUx_Tree_TreeGrid extends PhpExt_Tree_TreePanel
{
	public function __construct() {
		parent::__construct();
		$this->setExtClassInfo("Ext.ux.tree.TreeGrid",null);

		$validProps = array(
		    'columns'
		    ,'dataUrl'
		);
		$this->addValidConfigProperties($validProps);
	}
	
	public function setColumns($value) {
		$this->setExtConfigProperty("columns", $value);
		return $this;
	}
	
	public function dataUrl($value) {
		$this->setExtConfigProperty("dataUrl", $value);
		return $this;
	}
	
	/**
	 * @param  $value gia tri dinh nghia cac column cua tree
	 */
	public function setColumnsVariable($value) {
    	$this->setExtConfigProperty("columns", $value);
    	return $this;
    }
}